package com.pingan.generator.api.controller;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.pingan.generator.api.entity.BaseLog;
import com.pingan.generator.api.entity.{className}
import com.pingan.generator.api.entity.Pager;
import com.pingan.generator.api.entity.util.Response;
import com.pingan.generator.api.service.{className}Service;

@RestController
@RequestMapping("/{lowerFirstClassName}")
public class {className}Controller extends BaseLog{
	
	 @Autowired
	 private {className}Service {lowerFirstClassName}Service;

	@RequestMapping(value="/save{className}",method = RequestMethod.POST)
	@SuppressWarnings("unchecked")
	public Response<{className}> save{className}(@RequestBody {className} {lowerFirstClassName},HttpServletRequest request){
		int count = {lowerFirstClassName}Service.save({lowerFirstClassName});
		if(count>1){
			return Response.success(null);
		}
		return Response.failure();
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value="/query{className}PagedList",method = RequestMethod.POST)
	public Response<PageInfo<{className}>> query{className}PagedList(@RequestBody Pager pager){
		 if (pager.getParams() == null) {
	            pager.setParams(new HashMap<String, Object>());
	     }
		return Response.success({lowerFirstClassName}Service.pagedList(pager));
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/delete{className}", method = RequestMethod.POST)
	public Response<{className}> delete{className}(@RequestBody {className} {lowerFirstClassName}, HttpServletRequest request) {
		int count = {lowerFirstClassName}Service.deleteById({lowerFirstClassName});
		if(count>1){
			return Response.success(null);
		}
		return Response.failure();
	}
	
	@RequestMapping(value = "/delete{className}ByKey", method = RequestMethod.POST)
	public Response<{className}> delete{className}ByKey(String id, HttpServletRequest request) {
	    int  count = {lowerFirstClassName}Service.deleteById(id);
	    if(count>1){
			return Response.success(null);
		}
	    return Response.failure();
	}
}
